﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BaseCardTypes = Wormhole.Engine.CardLibrary.BaseCardTypes;
using CardTypes = Wormhole.Engine.CardLibrary.CardTypes;

namespace Wormhole.UI.Application.Controls.Cards
{
	/// <author>Rodney McKay</author>
	/// <date>08 April 2008</date>
	/// <summary>
	/// Render a support card in the play.
	/// </summary>
	public class SupportCard : Card
	{
		#region User Interface Elements
		/// <summary>
		/// Glyphs that was earned.
		/// </summary>
		protected Glyphs.GlyphLayout glyphs;
		#endregion

		#region Constructor
		/// <summary>
		/// Initialize a default instance of the class.
		/// </summary>
		public SupportCard() : base()
		{
		}

		/// <summary>
		/// Create a new instance of the control to render the specific card.
		/// </summary>
		/// <param name="card">The engine card that should be rendered.</param>
		public SupportCard(BaseCardTypes.Card card)
			: base(card)
		{
			this.CreateDisplayControls();
		}
		#endregion

		#region Set Size
		/// <summary>
		/// Set the card size.
		/// </summary>
		protected override void SetSize()
		{
			this.cardImage.Width = 131 * 0.7;
			this.cardImage.Height = 121 * 0.7;
			this.cardImage.Stretch = Stretch.Fill;

			this.outsideBorder.Width = this.cardImage.Width + 10;
			this.outsideBorder.Height = this.cardImage.Height + 10;

			this.Width = this.outsideBorder.Width;
			this.Height = this.outsideBorder.Height;
		}
		#endregion

		#region Display Status
		/// <summary>
		/// Draw a border around the card if it can be assigned to the current mission.
		/// </summary>
		public override void DisplayStatus()
		{
			base.DisplayStatus();

			CardTypes.Character character = this.EngineCard as CardTypes.Character;

			if (this.EngineCard.InputStatus == BaseCardTypes.InputStatus.AllowAssign)
			{
				if (character != null)
				{
					if (character.CanAssign())
						this.glowEffect.Opacity = 1;
					else
						this.glowEffect.Opacity = 0;
				}
			}
		}
		#endregion

		#region Create Child Controls
		/// <summary>
		/// Initialize the glyph control.
		/// </summary>
		protected virtual void CreateDisplayControls()
		{
			if (this.EngineCard != null)
			{
				if (this.EngineCard is CardTypes.Character)
				{
					// create the glyph control
					this.glyphs = new Wormhole.UI.Application.Controls.Glyphs.GlyphLayout();
					this.glyphs.TeamCard = this.EngineCard as CardTypes.Character;
					this.glyphs.HorizontalAlignment = HorizontalAlignment.Right;
					this.glyphs.VerticalAlignment = VerticalAlignment.Top;
					this.glyphs.Margin = new Thickness(0, 23, 5, 15);

					this.contentGrid.Children.Add(this.glyphs);
				}
			}
		}
		#endregion

	}
}
